/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lab2;

import actions.main.ChangeShownUserAction;
import actions.main.DeleteTaskAction;
import actions.main.ShowAllTasksAction;
import actions.main.ShowCreatedByMeTasksAction;
import actions.main.ShowTasksAction;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.UUID;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import models.MainWindowModel;

/**
 *
 * @author Кирилл
 */
public class MainWindow extends javax.swing.JFrame {

    /**
     * Creates new form MainWindow
     */
    
    
    private EditWindow ew;
    private static DefaultListModel listModel;
    private Thread ws;
    private static AlertMultiTaskWindow alert = AlertMultiTaskWindow.getInstance();
    private MainWindowModel mwm = new MainWindowModel();
    
    public MainWindow() {
        initComponents();
        listModel  = new DefaultListModel();
        fromLabel.setVisible(false);
        untilLabel.setVisible(false);
        untilDayBox.setVisible(false);
        untilMonthsBox.setVisible(false);
        untilYearBox.setVisible(false);
        taskList.setModel(listModel);
        ws = new WarningSystem();
        ws.start();
        AuthorizationWindow auth = new AuthorizationWindow(this, true);
        auth.setVisible(true);
        Manager.getInstance().startJob();
        //получение с сервера данных о задачах пользователя, о подчиненных пользователя и их задачах
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        addButton = new javax.swing.JButton();
        showBox = new javax.swing.JComboBox();
        fromDayBox = new javax.swing.JComboBox();
        fromMonthsBox = new javax.swing.JComboBox();
        fromYearBox = new javax.swing.JComboBox();
        untilDayBox = new javax.swing.JComboBox();
        untilMonthsBox = new javax.swing.JComboBox();
        untilYearBox = new javax.swing.JComboBox();
        taskPane = new javax.swing.JScrollPane();
        taskList = new javax.swing.JList();
        editButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        fromLabel = new javax.swing.JLabel();
        untilLabel = new javax.swing.JLabel();
        showAllButton = new javax.swing.JButton();
        showButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        chooseUserBox = new javax.swing.JComboBox();
        ShowCompletedTasksBox = new javax.swing.JCheckBox();
        showCreatedByMeTasksBox = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        addButton.setText("Add Task");
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });

        showBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Show day", "Show period" }));
        showBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showBoxActionPerformed(evt);
            }
        });

        fromMonthsBox.setModel(new DefaultComboBoxModel(Helper.getMonths()));
        fromMonthsBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fromMonthsBoxActionPerformed(evt);
            }
        });

        fromYearBox.setModel(new DefaultComboBoxModel(Helper.getYears(2012, 2015)));
        fromYearBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fromYearBoxActionPerformed(evt);
            }
        });

        untilMonthsBox.setModel(new DefaultComboBoxModel(Helper.getMonths()));
        untilMonthsBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                untilMonthsBoxActionPerformed(evt);
            }
        });

        untilYearBox.setModel(new DefaultComboBoxModel(Helper.getYears(2012, 2015)));
        untilYearBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                untilYearBoxActionPerformed(evt);
            }
        });

        taskList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        taskList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                taskListMouseClicked(evt);
            }
        });
        taskPane.setViewportView(taskList);

        editButton.setText("Edit Task");
        editButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editButtonActionPerformed(evt);
            }
        });

        deleteButton.setText("Delete Task");
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        fromLabel.setText("from");

        untilLabel.setText("until");

        showAllButton.setText("Show All Tasks");
        showAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showAllButtonActionPerformed(evt);
            }
        });

        showButton.setText("Show");
        showButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showButtonActionPerformed(evt);
            }
        });

        jLabel1.setText("Show tasks for:");

        chooseUserBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        chooseUserBox.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                chooseUserBoxPropertyChange(evt);
            }
        });

        ShowCompletedTasksBox.setText("Show only completed tasks");
        ShowCompletedTasksBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ShowCompletedTasksBoxActionPerformed(evt);
            }
        });

        showCreatedByMeTasksBox.setText("Show only tasks which was created by me");
        showCreatedByMeTasksBox.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                showCreatedByMeTasksBoxStateChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(showAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(addButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(29, 29, 29)
                        .addComponent(showBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(fromLabel)
                            .addComponent(untilLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(untilDayBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(fromDayBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(fromMonthsBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(untilMonthsBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(untilYearBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(fromYearBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(showButton))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(taskPane, javax.swing.GroupLayout.PREFERRED_SIZE, 469, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(deleteButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(editButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(57, 57, 57)
                                .addComponent(chooseUserBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(showCreatedByMeTasksBox)
                                .addGap(18, 18, 18)
                                .addComponent(ShowCompletedTasksBox)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(chooseUserBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addButton)
                    .addComponent(showBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fromDayBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fromMonthsBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fromYearBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fromLabel)
                    .addComponent(showButton))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(untilDayBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(untilMonthsBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(untilYearBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(untilLabel)
                    .addComponent(showAllButton))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(showCreatedByMeTasksBox)
                            .addComponent(ShowCompletedTasksBox))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(taskPane, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addComponent(editButton)
                        .addGap(54, 54, 54)
                        .addComponent(deleteButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void fromMonthsBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fromMonthsBoxActionPerformed
        // TODO add your handling code here:
        int fixedDay = fromDayBox.getSelectedIndex();
        String month = fromMonthsBox.getSelectedItem().toString();
        int year = Integer.parseInt(fromYearBox.getSelectedItem().toString());
        boolean isLeap = ("February".equals(month) && new GregorianCalendar().isLeapYear(year)) ? true : false;
        fromDayBox.setModel(new DefaultComboBoxModel(Helper.getDays(month, isLeap)));
        try {
            fromDayBox.setSelectedIndex(fixedDay);
        } catch (IllegalArgumentException ex) {
            fromDayBox.setSelectedIndex(0);
        }
    }//GEN-LAST:event_fromMonthsBoxActionPerformed

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
        // TODO add your handling code here: 
        ew = new EditWindow(this, true, true);
        Calendar now = Calendar.getInstance();
        System.out.println((String)chooseUserBox.getSelectedItem());
        ew.recieveData(new Task(UUID.randomUUID(), (String)chooseUserBox.getSelectedItem(), "New Task", "Description", now, now, "Some info", now, 0, 0));
        ew.setVisible(true);
    }//GEN-LAST:event_addButtonActionPerformed

    private void showBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showBoxActionPerformed
        // TODO add your handling code here:
        if ("Show period".equals((String) showBox.getSelectedItem())) {
            fromLabel.setVisible(true);
            untilLabel.setVisible(true);
            untilDayBox.setVisible(true);
            untilMonthsBox.setVisible(true);
            untilYearBox.setVisible(true);
            untilYearBox.setSelectedIndex(fromYearBox.getSelectedIndex());
            untilMonthsBox.setSelectedIndex(fromMonthsBox.getSelectedIndex());
            untilDayBox.setSelectedIndex(fromDayBox.getSelectedIndex());
        } else {
            fromLabel.setVisible(false);
            untilLabel.setVisible(false);
            untilDayBox.setVisible(false);
            untilMonthsBox.setVisible(false);
            untilYearBox.setVisible(false);
        }
    }//GEN-LAST:event_showBoxActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        // TODO add your handling code here:
        if (!taskList.isSelectionEmpty()) {
           // Task temp = (Task) taskList.getSelectedValue();
            //Manager.getInstance().removeTask(temp.getID());
            mwm.setSelectedTask((Task) taskList.getSelectedValue());
            new DeleteTaskAction().doAction(mwm);
            showButtonActionPerformed(null);
        } else {
            JOptionPane.showMessageDialog(this, "No one task has been selected");
        }

    }//GEN-LAST:event_deleteButtonActionPerformed

    private void fromYearBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fromYearBoxActionPerformed
        // TODO add your handling code here:
        String month = (String) fromMonthsBox.getSelectedItem();
        int year = Integer.parseInt((String) fromYearBox.getSelectedItem());
        if ("February".equals(month)) {
            fromDayBox.setModel(new DefaultComboBoxModel(Helper.getDays(month, new GregorianCalendar().isLeapYear(year))));
        }
    }//GEN-LAST:event_fromYearBoxActionPerformed

    private void untilMonthsBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_untilMonthsBoxActionPerformed
        // TODO add your handling code here:
        int fixedDay = untilDayBox.getSelectedIndex();
        String month = (String) untilMonthsBox.getSelectedItem();
        int year = Integer.parseInt(untilYearBox.getSelectedItem().toString());
        boolean isLeap = ("February".equals(month) && new GregorianCalendar().isLeapYear(year)) ? true : false;
        untilDayBox.setModel(new DefaultComboBoxModel(Helper.getDays(month, isLeap)));
        try {
            untilDayBox.setSelectedIndex(fixedDay);
        } catch (IllegalArgumentException ex) {
            untilDayBox.setSelectedIndex(0);
        }
    }//GEN-LAST:event_untilMonthsBoxActionPerformed

    private void untilYearBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_untilYearBoxActionPerformed
        // TODO add your handling code here:
        String month = (String) untilMonthsBox.getSelectedItem();
        int year = Integer.parseInt((String) untilYearBox.getSelectedItem());
        if ("February".equals(month)) {
            untilDayBox.setModel(new DefaultComboBoxModel(Helper.getDays(month, new GregorianCalendar().isLeapYear(year))));
        }
    }//GEN-LAST:event_untilYearBoxActionPerformed

    private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
        // TODO add your handling code here:
        if (!taskList.isSelectionEmpty()) {
            ew = new EditWindow(this, true, false);
            ew.recieveData((Task)taskList.getSelectedValue());
            ew.setVisible(true);
        } else {
            JOptionPane.showMessageDialog(this, "No one task has been selected");
        }
    }//GEN-LAST:event_editButtonActionPerformed

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
        // TODO add your handling code here:
        taskList.clearSelection();
    }//GEN-LAST:event_formMouseClicked

    private void taskListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_taskListMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 2 && listModel.getSize() != 0) {
            editButtonActionPerformed(null);
        }
    }//GEN-LAST:event_taskListMouseClicked

    private void showAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showAllButtonActionPerformed
        // TODO add your handling code here:
        listModel.clear();
        new ShowAllTasksAction().doAction(mwm);
        Task temp;
        Iterator i = mwm.getTasks().iterator();
        while (i.hasNext()) {
            temp = (Task) i.next();
            listModel.addElement(temp);
        }
    }//GEN-LAST:event_showAllButtonActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        Manager.getInstance().endJob();
    }//GEN-LAST:event_formWindowClosing

    private void showButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showButtonActionPerformed
        // TODO add your handling code here:
        listModel.clear();
        try {
            if (showBox.getSelectedIndex() == 0) {
                mwm.setShowPeriod(false);
                Calendar startTime = Calendar.getInstance();
                startTime.set(Integer.parseInt(fromYearBox.getSelectedItem().toString()),
                        fromMonthsBox.getSelectedIndex(),
                        Integer.parseInt(fromDayBox.getSelectedItem().toString()), 0, 0, 0);
                mwm.setStartTime(startTime);
                //tasks = Manager.getInstance().getByDay(startTime);
            } else {
                mwm.setShowPeriod(true);
                Calendar startTime = Calendar.getInstance();
                startTime.set(Integer.parseInt(fromYearBox.getSelectedItem().toString()),
                        fromMonthsBox.getSelectedIndex(),
                        Integer.parseInt(fromDayBox.getSelectedItem().toString()), 0, 0, 0);
                Calendar endTime = Calendar.getInstance();
                endTime.set(Integer.parseInt(untilYearBox.getSelectedItem().toString()),
                        untilMonthsBox.getSelectedIndex(),
                        Integer.parseInt(untilDayBox.getSelectedItem().toString()), 0, 0, 0);
                if (startTime.after(endTime)) {
                    throw new IllegalArgumentException();
                }
                mwm.setStartTime(startTime);
                mwm.setEndTime(endTime);
                //tasks = Manager.getInstance().getGap(startTime, endTime);
            }
            new ShowTasksAction().doAction(mwm);
            Task temp;
            Iterator i = mwm.getTasks().iterator();
            while (i.hasNext()) {
                temp = (Task) i.next();
                listModel.addElement(temp);
            }
        } catch (IllegalArgumentException ex) {
            JOptionPane.showMessageDialog(this, "End Date is lesser than start date");
        } catch (NullPointerException ex){
        }
    }//GEN-LAST:event_showButtonActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        Calendar now = Calendar.getInstance();
        fromMonthsBox.setSelectedIndex(now.get(GregorianCalendar.MONTH));
        fromDayBox.setSelectedIndex(now.get(GregorianCalendar.DAY_OF_MONTH) - 1);
        fromYearBox.setSelectedIndex(now.get(GregorianCalendar.YEAR) - 2012);
        //List<Task> deprecatedTasks = Manager.getInstance().getDeprecatedTasks();
        showButtonActionPerformed(null);
        if (alert.checkTasks()){
            alert.setVisible(true);
        }
        //showButtonActionPerformed(null);
    }//GEN-LAST:event_formWindowOpened

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
        showButtonActionPerformed(null);
    }//GEN-LAST:event_formWindowActivated

    private void ShowCompletedTasksBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ShowCompletedTasksBoxActionPerformed
        // TODO add your handling code here:
        mwm.setShowCompletedTasks(ShowCompletedTasksBox.isSelected());
        new ShowAllTasksAction().doAction(mwm);
    }//GEN-LAST:event_ShowCompletedTasksBoxActionPerformed

    private void showCreatedByMeTasksBoxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_showCreatedByMeTasksBoxStateChanged
        // TODO add your handling code here:
        mwm.setCreatedByMeTasks(showCreatedByMeTasksBox.isSelected());
        new ShowCreatedByMeTasksAction().doAction(mwm);
    }//GEN-LAST:event_showCreatedByMeTasksBoxStateChanged

    private void chooseUserBoxPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_chooseUserBoxPropertyChange
        // TODO add your handling code here:
        mwm.setCurrentUser((String)chooseUserBox.getSelectedItem());
        new ChangeShownUserAction().doAction(mwm);
    }//GEN-LAST:event_chooseUserBoxPropertyChange

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainWindow().setVisible(true);
            }
        });
    }


    public static void showAlert(Calendar time) {
        //List<Task> tasks = Manager.getInstance().getTasks(time);
        alert.addTasks(time);
        alert.setVisible(true);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox ShowCompletedTasksBox;
    private javax.swing.JButton addButton;
    private javax.swing.JComboBox chooseUserBox;
    private javax.swing.JButton deleteButton;
    private javax.swing.JButton editButton;
    private javax.swing.JComboBox fromDayBox;
    private javax.swing.JLabel fromLabel;
    private javax.swing.JComboBox fromMonthsBox;
    private javax.swing.JComboBox fromYearBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton showAllButton;
    private javax.swing.JComboBox showBox;
    private javax.swing.JButton showButton;
    private javax.swing.JCheckBox showCreatedByMeTasksBox;
    private javax.swing.JList taskList;
    private javax.swing.JScrollPane taskPane;
    private javax.swing.JComboBox untilDayBox;
    private javax.swing.JLabel untilLabel;
    private javax.swing.JComboBox untilMonthsBox;
    private javax.swing.JComboBox untilYearBox;
    // End of variables declaration//GEN-END:variables
}
